#include "DeclareFile.h"
#include <time.h>

// 切换播放上下左右的图片
#define UPMOVE 1
#define DOWNMOVE 2
#define RIGHTMOVE 3
#define LEFTMOVE 4

//生成吸血鬼
void CreatMonster() {

	srand(time(NULL));
	//BeginBatchDraw();
	//cleardevice();

	int frames = 9; // 图片动作
	static int index = 5; // 播放第几-1张图片
	static int imgX1 = rand() % getwidth(); // 图片x坐标
	static int imgY1 = rand() % getheight(); // 图片y坐标

	static int imgX2 = rand() % getwidth(); // 图片x坐标
	static int imgY2 = rand() % getheight(); // 图片y坐标

	static int imgX3 = rand() % getwidth(); // 图片x坐标
	static int imgY3 = rand() % getheight(); // 图片y坐标

	static int imgX4 = rand() % getwidth(); // 图片x坐标
	static int imgY4 = rand() % getheight(); // 图片y坐标
	int imgWidth; // 图片宽度
	int imgHeight; // 图片高度
	int speed = 200; // 播放速度

	imgWidth = 64;
	imgHeight = 66;


	static int frame = 1;


	if (imgY1 <= -imgHeight) {
		//imgX1 = rand() % 800;
		imgY1 = 600;
	}
	if (imgY2 >= 600) {
		//imgX2 = rand() % 800;
		imgY2 = 0;
	}
	if (imgX3 >= 800) {
		//imgY1 = rand() % 600;
		imgX3 = 0;
	}
	if (imgX4 <= -imgWidth) {
		//imgY2 = rand() % 600;
		imgX4 = 800 - imgWidth;
	}

	frame++;
	//BeginBatchDraw();
	if (frame >= 40) {

		frame = 1;
		switch (1)
		{
		case UPMOVE:
			putimage(imgX1, imgY1, imgWidth, imgHeight, &MonsterUpImg, index * imgWidth, 0);

			imgY1 -= 2;
			//Sleep(100);
			//break;
		case DOWNMOVE:
			putimage(imgX2, imgY2, imgWidth, imgHeight, &MonsterDownImg, index * imgWidth, 0);
			imgY2 += 2;
			//Sleep(100);
			//break;
		case RIGHTMOVE:
			putimage(imgX3, imgY3, imgWidth, imgHeight, &MonsterRightImg, index * imgWidth, 0);
			imgX3 += 2;
			//Sleep(100);
			//break;
		case LEFTMOVE:
			putimage(imgX4, imgY4, imgWidth, imgHeight, &MonsterLeftImg, index * imgWidth, 0);
			imgX4 -= 2;
			//Sleep(50);
			//break;
		}
		index = (clock() / speed) % frames;
		//FlushBatchDraw();
	}
	//FlushBatchDraw();

}